package com.kcsj.demo.Controller;

import com.kcsj.demo.Mapper.SupplierMapper;
import com.kcsj.demo.Module.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Controller
public class SupplierController {
    @Autowired
    SupplierMapper supplierMapper;
    @GetMapping("supplier")
    public String supplierController(Map<String,Object> map){
        map.put("list", supplierMapper.list());
        return "supplier";
    }
    @PostMapping("supplier_insert")
    public String supplierInsert(@RequestParam(name = "name_supplier") String userName,
                                 @RequestParam(name = "supplier_company") String supplierCompany,
                                 @RequestParam(name = "supplier_telephone") long supplierTelephone){
        Supplier supplier = new Supplier();
        supplier.setName(userName);
        supplier.setCompany(supplierCompany);
        supplier.setTelephoneNumber(supplierTelephone);
        supplierMapper.insert(supplier);
        return "jump";
    }
    @PostMapping("del_supplier")
    public String delSupplier(@RequestParam(name = "del_sup") String name){
        supplierMapper.delete(name);
        return "jump";
    }
}
